<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="100px">
      <el-form-item label="日期查询" prop="createTime">
        <el-date-picker clearable size="small" v-model="queryParams.createTime" type="date" value-format="yyyy-MM-dd" placeholder="选择日期">
        </el-date-picker>
      </el-form-item>
      <el-form-item label="线索来源" prop="cluesSource">
        <el-select v-model="queryParams.cluesSource" placeholder="请选择线索来源" clearable size="small">
          <el-option v-for="dict in dict.type.clues_source" :key="dict.value" :label="dict.label" :value="dict.value" />
        </el-select>
      </el-form-item>
      <el-form-item label="联系电话" prop="phone">
        <el-input v-model="queryParams.phone" placeholder="请输入联系电话" clearable size="small" @keyup.enter.native="handleQuery" />
      </el-form-item>
      <el-form-item label="转成客户状态" prop="phone">
        <el-select v-model="queryParams.state" placeholder="请选择转成客户状态" clearable size="small">
          <el-option label="否" value="0" />
          <el-option label="是" value="1" />
        </el-select>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button type="primary" plain icon="el-icon-plus" size="mini" @click="handleAdd" v-hasPermi="['crm:pool:add']">添加线索</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="warning" plain icon="el-icon-s-promotion" size="mini" :disabled="!selected" @click="handleTransfer" v-hasPermi="['crm:clues:transfer']">转移线索</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button type="info" plain icon="el-icon-download" size="mini" @click="handleExport_" v-hasPermi="['crm:customer:export']">导出</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>

    <el-table :border="true" v-loading="loading" :data="customerList" @selection-change="handleSelectionChange" :show-summary="bc" :summary-method="getSummaries">
      <el-table-column type="selection" width="80" align="center" />
      <el-table-column label="线索名称" align="center" prop="cluesName" :show-overflow-tooltip="true" width="220" />
      <el-table-column label="联系电话" align="center" prop="phone" :show-overflow-tooltip="true" width="200" />
      <el-table-column label="线索状态" align="center" prop="cluesStatus" :show-overflow-tooltip="true" width="200">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.clues_status" :value="scope.row.cluesStatus" width="200" />
        </template>
      </el-table-column>
      <!-- 添加部分字段:北创 -->
      <template v-if="bc">
      <el-table-column label="线索进展" align="center" prop="advice" :show-overflow-tooltip="true" width="200"></el-table-column>
      <el-table-column label="我的报价" align="center" prop="myQuote" :show-overflow-tooltip="true" width="200"></el-table-column>
      <el-table-column label="成交情况" align="center" prop="isDeal" :show-overflow-tooltip="true" width="200">
        <template slot-scope="scope">
          {{ scope.row.isDeal ? '已成交' : '未成交' }}
        </template>
      </el-table-column>
      <el-table-column label="成交金" align="center" prop="dealAmount" :show-overflow-tooltip="true" width="200"></el-table-column>
      </template>
      <!---->
      <el-table-column label="线索来源" align="center" prop="cluesSource" :show-overflow-tooltip="true" width="200">
        <template slot-scope="scope">
          <dict-tag :options="dict.type.clues_source" :value="scope.row.cluesSource" />
        </template>
      </el-table-column>
      <el-table-column label="地区来源" align="center" prop="region" :show-overflow-tooltip="true" width="240">
        <!-- <template slot-scope="scope">
          <dict-tag :options="dict.type.region_list" :value="scope.row.region" />
        </template> -->
      </el-table-column>

      <el-table-column label="转成客户状态" align="center" prop="state" :show-overflow-tooltip="true" width="240">
        <template slot-scope="scope">
          {{ scope.row.state == '1' ? '是' : '否' }}
        </template>
      </el-table-column>

      <el-table-column label="负责人" align="center" prop="owner" :show-overflow-tooltip="true" width="200" />
      <el-table-column label="创建时间" align="center" prop="createTime" width="180" :show-overflow-tooltip="true">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime) }}</span>
        </template>
      </el-table-column>
      <el-table-column label="操作" align="left" class="small-padding" width="300px">
        <template slot-scope="scope">
          <el-button size="mini" type="text" icon="el-icon-s-promotion" @click="handleTransfer(scope.row)" v-hasPermi="['crm:clues:transfer']" v-if="scope.row.state!='1'">转移</el-button>
          <el-button size="mini" type="text" icon="el-icon-refresh-left" @click="handleToCustomer(scope.row)" v-hasPermi="['crm:clues:tocustomer']" v-if="scope.row.state!='1'">转成客户</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['crm:clues:edit']" v-if="scope.row.state!='1'">修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handledetail(scope.row)" v-hasPermi="['crm:clues:edit']" v-if="scope.row.state!='1'">详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['crm:clues:remove']" v-if="scope.row.state!='1'">删除</el-button>

          <!-- <el-button size="mini" type="text" icon="el-icon-s-promotion" @click="handleTransfer(scope.row)" v-hasPermi="['crm:clues:transfer']" >转移</el-button>
          <el-button size="mini" type="text" icon="el-icon-refresh-left" @click="handleToCustomer(scope.row)" v-hasPermi="['crm:clues:tocustomer']" >转成客户</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handleUpdate(scope.row)" v-hasPermi="['crm:clues:edit']" >修改</el-button>
          <el-button size="mini" type="text" icon="el-icon-edit" @click="handledetail(scope.row)" v-hasPermi="['crm:clues:edit']" >详情</el-button>
          <el-button size="mini" type="text" icon="el-icon-delete" @click="handleDelete(scope.row)" v-hasPermi="['crm:clues:remove']" >删除</el-button> -->

        </template>
      </el-table-column>
    </el-table>

    <pagination v-show="total > 0" :total="total" :page.sync="queryParams.pageNum" :limit.sync="queryParams.pageSize" @pagination="getList" />

    <!-- 添加或修改线索对话框 -->
    <el-dialog :close-on-click-modal="false" :title="title" :visible.sync="open" width="680px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px" :disabled="title=='详情'">
        <el-row>
          <el-col :span="12">
            <el-form-item label="线索名称" prop="cluesName">
              <el-input v-model="form.cluesName" placeholder="请输入线索名称" :maxlength="32" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="地区" prop="region">
              <!-- <el-select v-model="form.region" placeholder="请选择地区">
                <el-option v-for="dict in dict.type.region_list" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
              </el-select> -->
              <Cascader @provincesValueChang="provincesValueChang" :value="form.region" style="width: 100%;"></Cascader>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="联系人" prop="linkman">
              <el-input v-model="form.linkman" placeholder="请输入联系人" :maxlength="32" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系电话" prop="phone">
              <el-input v-model="form.phone" placeholder="请输入联系电话" :maxlength="11" />
            </el-form-item>
          </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="线索来源" prop="cluesSource">
              <el-select v-model="form.cluesSource" placeholder="请选择线索来源" style="width: 100%">
                <el-option v-for="dict in dict.type.clues_source" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="线索状态" prop="cluesStatus">
              <el-select v-model="form.cluesStatus" placeholder="请选择线索状态" style="width: 100%">
                <el-option v-for="dict in dict.type.clues_status" :key="dict.value" :label="dict.label" :value="dict.value"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <template v-if="bc">
        <el-row>
          <el-col :span="12">
            <el-form-item label="线索进展" prop="cluesSource">
              <el-input v-model="form.advice" placeholder="请输入线索进展" />
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="我的报价" prop="cluesStatus">
              <el-input-number v-model="form.myQuote" :min="1" label="请输入报价"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :span="12">
            <el-form-item label="成交情况" prop="cluesSource">
              <el-select v-model="form.isDeal" placeholder="请选择成交状态" style="width: 100%">
                <el-option label="未成交" :value="0"></el-option>
                <el-option label="已成交" :value="1"></el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="成交金额" prop="cluesStatus">
              <el-input-number v-model="form.dealAmount" :min="1" label="请输入成交金额"></el-input-number>
            </el-form-item>
          </el-col>
        </el-row>
        </template>
        <el-form-item label="负责人" prop="">
          <el-select v-model="form.userName" filterable placeholder="请选择负责人" style="width: 100%">
            <el-option v-for="v,i in userList" :key="i" :label="v.nickName" :value="v.userName"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="备注" prop="remark">
          <el-input v-model="form.remark" type="textarea" placeholder="请输入内容" />
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm" v-if="title!='详情'">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

    <TransferCluesComponent v-if="transferClues" ref="transferClues" @close-dialog="handleTransferCluesClose" />
    <ToCustomerComponent v-if="toCustomer" ref="toCustomer" @close-dialog="handleToCustomerClose" />
  </div>
</template>

<script>
import {
  listClues,
  getClues,
  delClues,
  addClues,
  updateClues,
  reqUserList,
  toCustomer_before2,
  toCustomer_before1,
} from "@/api/crm/clues";
import { reqSendToken } from "@/api/login.js";
import TransferCluesComponent from "./Transfer";
import ToCustomerComponent from "./ToCustomer";
import Cascader from "@/components/Cascader/index.vue";
import { getUserInfoByToken } from "@/utils/toosls.js";
import axios from "axios";
export default {
  name: "Clues",
  components: {
    TransferCluesComponent,
    ToCustomerComponent,
    Cascader,
  },
  dicts: [
    "clues_source",
    "customer_industry",
    "clues_status",
    "customer_rank",
    "region_list",
    "customer_status",
  ],
  data() {
    return {
      visable: false,
      id_: "",
      code_: "",
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 是否勾选
      selected: false,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 线索表格数据
      customerList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        name: null,
        linkman: null,
        phone: null,
        region: null,
        customerIndustry: null,
        customerRank: null,
        customerStatus: null,
        cluesName: null,
        cluesSource: null,
        cluesStatus: null,
        manager: null,
        state: "0",
        // state:0,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        cluesName: [
          { required: true, message: "线索名称不能为空", trigger: "blur" },
        ],
        linkman: [
          { required: true, message: "联系人不能为空", trigger: "blur" },
        ],
        phone: [
          { required: true, message: "联系电话不能为空", trigger: "blur" },
        ],
      },
      transferClues: false,
      toCustomer: false,
      nickName: "",
      username: "",
      userList: [],
      bc:false, //北创功能: 客户关系管理模块-线索列表需增加以下字段:1，正在咨询，谈判 2，我的报价 3，成交情况:是/否 4，成交金额5，整个表单金额汇总6，表单导出功能
    };
  },
  created() {
    // this.queryParams.state='22'
    this.getList();
    this.getUserList();
    setTimeout(() => {
      this.getUserInfo();
    }, 300);
    //是否开启北创特有功能
    this.bc = process.env.VUE_APP_EXTENT_ENABLE == 'true' ? true : false;
  },
  methods: {
    /** 导出按钮操作 */
    handleExport_(event) {
      event.preventDefault();
      this.handleExport();
    },

    async handleExport() {
      const Authorization =
        "Bearer" +
        (localStorage.getItem("Token") ||
          "eyJhbGciOiJSUzI1NiIsInR5cCIgOiAiSldUIiwia2lkIiA6ICJmQm9wV2otVTFIYjlTa0ZHMHZYQ1lRVVhkRkdDMGhXRTBkVjJCN1FaSl9ZIn0.eyJleHAiOjE3NTExNzk5NzMsImlhdCI6MTc0NTk5NTk3MywianRpIjoiOGQ5YWEyY2MtMTI4Mi00OGZmLTg5ZjctNTY3ZGZiMjRkYWQyIiwiaXNzIjoiaHR0cDovLzE3Mi4xNi4wLjM6ODQxMS9hdXRoL3JlYWxtcy9lZGdlIiwiYXVkIjpbIm5vY29jb25zb2xlIiwiYWNjb3VudCIsIm9jcy1jb250cm9sbGVyIl0sInN1YiI6ImIwMjZiYzUxLTEzMjItNDJiOC1iZTg0LWU5MDJiNmFjYmM3YSIsInR5cCI6IkJlYXJlciIsImF6cCI6Imppbmd6aGkiLCJzZXNzaW9uX3N0YXRlIjoiMzgyZmFiNTktYWI0ZC00ZTZjLWJkNWMtNTNlZDIzYzM0ZDUwIiwiYWNyIjoiMSIsInJlYWxtX2FjY2VzcyI6eyJyb2xlcyI6WyLnsr7liLYt57O757uf566h55CG5ZGYIiwi57O757uf6L-Q57u0Iiwib2ZmbGluZV9hY2Nlc3MiLCJ1bWFfYXV0aG9yaXphdGlvbiIsImRlZmF1bHQtcm9sZXMtZWRnZSJdfSwicmVzb3VyY2VfYWNjZXNzIjp7Im5vY29jb25zb2xlIjp7InJvbGVzIjpbIm5vY29fY29uc29sZV9hZG1pbl9yb2xlIl19LCJhY2NvdW50Ijp7InJvbGVzIjpbIm1hbmFnZS1hY2NvdW50IiwibWFuYWdlLWFjY291bnQtbGlua3MiLCJ2aWV3LXByb2ZpbGUiXX0sIm9jcy1jb250cm9sbGVyIjp7InJvbGVzIjpbIm9jcy1jb250cm9sbGVyLWFkbWluLXJvbGUiLCJvY3MtY29udHJvbGxlci1yZWFkLXJvbGUiXX19LCJzY29wZSI6InByb2ZpbGUgZW1haWwiLCJzaWQiOiIzODJmYWI1OS1hYjRkLTRlNmMtYmQ1Yy01M2VkMjNjMzRkNTAiLCJlbWFpbF92ZXJpZmllZCI6ZmFsc2UsIm5hbWUiOiLmm77kuL3okI0iLCJwcmVmZXJyZWRfdXNlcm5hbWUiOiJ6ZW5nbHAiLCJnaXZlbl9uYW1lIjoi5pu-5Li96JCNIiwiZW1haWwiOiJ6ZW5nbHBAdGVzdC5jb20ifQ.BZ3FgWEKPTSZSc60sbf7u0dDGs5TiCZ6DOWMW4RLC16abjIS6ySYgLhRx_JAhKXmJjyk8DkrBu0lBs1mNy4lOJdkzkjzQ3CUDbt6xUodjCTxJJ0tAJF6DFdbh8g49QmHOZFkjszw9qzn6H_7b8HbD5Bv1JTv1LUOXvdmEu7whtUZOay3EX0UeqBFGhd4MmgYufr8r5rPoM4tp8haEz_kXWf_N_6o4XmpzqFvSwEOwg1QI6eiZaQpoEQLJq1skCOxFOAYHKZXA2AdbX0vB3W4UGT-ovwUJRV64OFv3AH8Tu59isgEmCSghgpbsxJZ96pAFYc0v_CgHFUZkIT2ngp3dQ");
      const url = localStorage
        .getItem("wsAddress")
        ?.replace("wss://", "https://");
      axios({
        url: url + "/factory/v1/jy-crm-app/crm/clues/exportTable",
        method: "post",
        responseType: "blob",
        // params: { userName: this.userNameId },
        headers: {
          Authorization,
        },
      })
        .then((response) => {
          // 请求成功，处理响应数据
          const url = window.URL.createObjectURL(
            new Blob([response.data], {
              type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
            })
          ); // 创建一个Blob对象，并生成一个URL
          const link = document.createElement("a"); // 创建一个临时的<a>标签用于下载
          link.href = url; // 设置<a>标签的href属性为Blob对象的URL
          link.setAttribute("download", "线索列表.xlsx"); // 设置下载文件名，扩展名根据实际文件类型设置
          document.body.appendChild(link); // 将<a>标签添加到页面中，以便可以点击
          link.click(); // 模拟点击<a>标签，触发下载
          document.body.removeChild(link); // 下载触发后，从页面中移除<a>标签
          window.URL.revokeObjectURL(url); // 释放创建的URL对象，避免内存泄漏
        })
        .catch((error) => {
          // 请求失败，处理错误
          console.error("下载文件失败:", error);
          alert("下载文件失败，请稍后重试或联系管理员");
        });
    },

    /** 查询线索列表 */
    getList() {
      this.loading = true;
      listClues(this.queryParams).then((response) => {
        console.log(response.rows, "===response.rows===");

        this.customerList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: null,
        name: null,
        linkman: null,
        phone: null,
        region: null,
        customerIndustry: null,
        customerRank: null,
        customerStatus: null,
        status: "0",
        cluesName: null,
        cluesSource: null,
        cluesStatus: null,
        dealStatus: "0",
        manager: null,
        delFlag: null,
        version: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        owner: "",
        userName: "",
        state: "0",
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.$refs.queryForm.resetFields();
      // 2. 强制设置state为'0'（确保响应式）
      this.$nextTick(() => {
        this.queryParams.state = "0"; // 必须与el-option的value类型一致
        this.handleQuery();
      });
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      this.selected = selection.length;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      if (this.username) {
        this.form.userName = this.username;
      }
      this.open = true;
      this.title = "添加线索";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids;

      getClues(id).then((response) => {
        this.form = response.data;
        // this.form.userName = response.data.owner || this.username;
        this.form.userName = response.data.userName || this.username;
        this.form.region = this.form.region.split(",");
        this.open = true;
        this.title = "修改线索";
      });
    },

    /** 详情按钮操作 */
    handledetail(row) {
      this.reset();
      const id = row.id || this.ids;
      getClues(id).then((response) => {
        this.form = response.data;
        // this.form.userName = response.data.owner || this.username;
        this.form.userName = response.data.userName || this.username;
        this.form.region = this.form.region.split(",");
        this.open = true;
        this.title = "详情";
      });
    },

    /** 提交按钮 */
    // submitForm_ () {
    //   this.$refs['form'].validate((valid) => {
    //     if (valid) {

    //       toCustomer_before1().then((res) => {
    //         console.log(res.data.data[0].id, "===发送第一个请求,获取到id===");
    //         this.id_ = +res.data.data[0].id;

    //         // console.log(this.id_, "===this.id_===");
    //         toCustomer_before2({ id: this.id_ }).then((res) => {
    //           console.log(
    //             res.data.data.code,
    //             "===发送第二个请求,获取到code==="
    //           );
    //           this.code_ = res.data.data.code;
    //           // console.log(this.code_, "===this.code_==");
    //           this.form.code = this.code_;
    //           // console.log(this.form.code, "===this.form.code==");

    //           if(this.form.region){
    //         this.form.region = this.form.region.join(",");
    //       }
    //       this.form. owner= this.userList.find(item => item.userName === this.form.userName).nickName;
    //       if (this.form.id != null) {
    //         updateClues(this.form).then((response) => {
    //           this.$modal.msgSuccess('修改成功')
    //           this.open = false
    //           this.getList()
    //         })
    //       } else {

    //         addClues(this.form).then((response) => {
    //         console.log(response, "==response新增==");

    //      if(response.code==200){
    //         this.$modal.msgSuccess("新增成功");
    //       this.open = false;
    //       this.getList();
    //       }
    //       else{
    //         this.$message.error("新增的客户编号重复");
    //         return false;

    //       }
    //       })

    //       }

    //         });

    //       });

    //       // if(this.form.region){
    //       //   this.form.region = this.form.region.join(",");
    //       // }
    //       // this.form. owner= this.userList.find(item => item.userName === this.form.userName).nickName;
    //       // if (this.form.id != null) {
    //       //   updateClues(this.form).then((response) => {
    //       //     this.$modal.msgSuccess('修改成功')
    //       //     this.open = false
    //       //     this.getList()
    //       //   })
    //       // } else {

    //       //   addClues(this.form).then((response) => {
    //       //     this.$modal.msgSuccess('新增成功')
    //       //     this.open = false
    //       //     this.getList()
    //       //   })
    //       // }
    //     }
    //   })
    // },

    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.region && Array.isArray(this.form.region)) {
            this.form.region = this.form.region.join(",");
          }
          this.form.owner = this.userList.find(
            (item) => item.userName === this.form.userName
          ).nickName;
          // console.log(this.form.id,'==this.form.id==');
          // console.log(this.form.code,'==this.form.code==');

          if (this.form.id != null) {
            updateClues(this.form).then((response) => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            toCustomer_before1().then((res) => {
              console.log(res.data.data[0].id, "===发送第一个请求,获取到id===");
              this.id_ = +res.data.data[0].id;
              console.log(this.id_, "===this.id_===");

              toCustomer_before2({ id: this.id_ }).then((res) => {
                console.log(
                  res.data.data.code,
                  "===发送第二个请求,获取到code==="
                );
                this.code_ = res.data.data.code;
                console.log(this.code_, "===this.code_==");
                this.form.code = this.code_;
                console.log(this.form.code, "===this.form.code==");

                addClues(this.form).then((response) => {
                  console.log(response, "==response新增==");

                  if (response.code == 200) {
                    this.$modal.msgSuccess("新增成功");
                    this.open = false;
                    this.getList();
                  } else {
                    this.$message.error("新增的客户编号重复");
                    return false;
                  }
                });
              });
            });
          }
        }
      });
    },

    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      this.$modal
        .confirm('是否确认删除线索编号为"' + ids + '"的数据项？')
        .then(function () {
          return delClues(ids);
        })
        .then(() => {
          this.getList();
          this.$modal.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    // handleExport () {
    //   this.download(
    //     '/crm/clues/export',
    //     {
    //       ...this.queryParams,
    //     },
    //     `我的线索_${new Date().getTime()}.xlsx`
    //   )
    // },
    handleTransfer(row) {
      console.log(row);
      const ids = row.id || this.ids.join(",");
      this.transferClues = true;
      this.$nextTick(() => {
        this.$refs.transferClues.open(ids);
      });
    },
    handleTransferCluesClose() {
      this.transferClues = false;
      this.getList();
    },
    handleToCustomer(row) {
      const id = row.id;
      this.toCustomer = true;
      this.$nextTick(() => {
        this.$refs.toCustomer.open(id);
      });
      // console.log(this.visable,'==this.visable==');
      // this.visable=true
      // console.log(this.visable,'==this.visable==');
      row.state = 1;
      console.log(row.state, "=== row.state===");
    },

    handleConvertSuccess(data) {
      // 转化成功后的处理，如刷新列表
      this.$message.success("客户转化成功");
      this.getList();
    },

    handleToCustomerClose() {
      this.toCustomer = false;
      this.getList();
    },
    provincesValueChang(value) {
      this.form.region = value;
    },
    getUserInfo() {
      const userInfo = getUserInfoByToken();
      const { preferred_username, given_name } = userInfo;
      this.username = preferred_username; //zenglp
      this.nickName = given_name; //曾
      this.getList();
      /* reqSendToken().then(response => {
        const data = JSON.parse(response.data);
        const nickName = data.data.nickname;
        this.nickName = nickName; 
        this.username = data.data.username;
        console.log('请求用户信息',data);
      }).catch(error => {
        console.log('请求用户信息',error);
      }) */
    },
    //获取负责人列表信息
    getUserList() {
      reqUserList()
        .then((response) => {
          if (response.code === 200) {
            const tmp = response.data;
            this.userList = tmp;
          }
          console.log("获取负责人列表信息", response);
        })
        .catch((error) => {
          console.log("获取负责人列表信息", error);
        });
    },
    getSummaries(parameter) {
      const { columns, data } = parameter;
      const calculateList = new Array();
      //需要进行累计求和的字段名称
      const fieldList = ["myQuote", "dealAmount"];
      for (let col = 0; col < columns.length; col++) {
        let calculateListValue = null;
        if (
          columns[col].property &&
          fieldList.includes(columns[col].property)
        ) {
          const num = data.reduce(
            (pre, cur) => pre + Number(cur[columns[col].property]),
            0
          );
          calculateList.push(num);
        } else {
          col === 0 ? calculateList.push("合计") : calculateList.push("");
        }
      }
      return calculateList;
    },
  },
};
</script>
